#include "gui/layers/MapLayer.h"
#include "gui/util/GUIObjectDrawer.h"

namespace gui {

MapLayer::MapLayer(GUIMap* guiMap): Layer() {
	delete this->completeSurface;
	this->completeSurface = new Surface(guiMap->getTotalWidth(), guiMap->getTotalHeight(), 0, 0, 0);
	GUIObjectDrawer drawer;
	util::LinkedList<GUIObject>::Iterator it = guiMap->getGUIObjects().iterator();
	while (it.hasNext()) {
		GUIObject* current = it.next();
		Surface* surface = drawer.drawGUIObject(current);
		Portion position;
		position.x = (current->getXPos() - surface->getWidth() / 2) - guiMap->getLeftLimit();
		position.y = (current->getYPos() - surface->getHeight() / 2) - guiMap->getTopLimit();
		completeSurface->applySurface(surface, position);
		delete surface;
	}
}

MapLayer::~MapLayer() {

}

}
